//
//  SettingView.m
//  YouWen
//
//  Created by 刘永和 on 15/3/9.
//  Copyright (c) 2015年 刘永和. All rights reserved.
//

#import "SettingView.h"

@implementation SettingView
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}
-(void)createSubView
{
    
    self.backgroundColor = [NightModeHandle shareNightModeHandle].allViewColor;
    
    
    //清除缓存动画view
    self.cleanView = [[UIView alloc] initWithFrame:CGRectMake(15, 20, self.frame.size.width - 30, 100)];
    self.cleanView.backgroundColor = [UIColor colorWithRed:162/255.0 green:135/255.0 blue:191/255.0 alpha:1.0];
    //  设置圆角
    self.cleanView.layer.cornerRadius = 15;
    // 这个不知道是啥 设不设置都没影响
    self.cleanView.layer.masksToBounds = NO;
    [self addSubview:self.cleanView];
    
    
    //清除缓存
    self.cleanButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.cleanButton.frame = CGRectMake(135, 50, 100, 40);
//    self.cleanButton.backgroundColor = [UIColor redColor];
    [self.cleanButton setTitle:@"清除缓存" forState:UIControlStateNormal];
    [self.cleanButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.cleanButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [self.cleanButton addTarget:self action:@selector(cleanButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //  设置圆角
    self.cleanButton.layer.cornerRadius = 20;
    // 这个不知道是啥 设不设置都没影响
    self.cleanButton.layer.masksToBounds = NO;
    [self addSubview:self.cleanButton];
    
    
    
    //夜间模式动画view
    self.nightModeView = [[UIView alloc] initWithFrame:CGRectMake(15, 150, self.frame.size.width - 30, 100)];
    self.nightModeView.backgroundColor = [NightModeHandle shareNightModeHandle].nightModeColor;
    //  设置圆角
    self.nightModeView.layer.cornerRadius = 15;
    // 这个不知道是啥 设不设置都没影响
    self.nightModeView.layer.masksToBounds = NO;
    [self addSubview:self.nightModeView];
    
    //夜间模式
    self.nightModeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.nightModeButton.frame = CGRectMake(self.cleanButton.frame.origin.x, 180, 100, 40);
//    self.nightModeButton.backgroundColor = [UIColor redColor];
    [self.nightModeButton setTitle:@"夜间模式" forState:UIControlStateNormal];
    [self.nightModeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.nightModeButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [self.nightModeButton addTarget:self action:@selector(nightModeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //  设置圆角
    self.nightModeButton.layer.cornerRadius = 20;
    // 这个不知道是啥 设不设置都没影响
    self.nightModeButton.layer.masksToBounds = NO;
    [self addSubview:self.nightModeButton];
    
    
    //字体大小动画view
    self.wordSizeView = [[UIView alloc] initWithFrame:CGRectMake(15, 280, self.frame.size.width - 30, 150)];
    self.wordSizeView.backgroundColor = [WordSizeHandle shareWordSizeHandle].wordViewColor;
    //  设置圆角
    self.wordSizeView.layer.cornerRadius = 15;
    // 这个不知道是啥 设不设置都没影响
    self.wordSizeView.layer.masksToBounds = NO;
    [self addSubview:self.wordSizeView];
    
    
    //字体大小label
    self.wordSizeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.cleanButton.frame.origin.x, 310, 100, 40)];
    self.wordSizeLabel.text = @"字体大小";
    self.wordSizeLabel.font = [UIFont systemFontOfSize:19];
//    self.wordSizeLabel.backgroundColor = [UIColor redColor];
    self.wordSizeLabel.textColor = [UIColor whiteColor];
    self.wordSizeLabel.textAlignment = UITextAlignmentCenter;
    [self addSubview:self.wordSizeLabel];
    
    //大button
    self.bigButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.bigButton.frame = CGRectMake(37, 370, 100, 40);
//    self.bigButton.backgroundColor = [UIColor redColor];
    [self.bigButton setTitle:@"大" forState:UIControlStateNormal];
    [self.bigButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.bigButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [self.bigButton addTarget:self action:@selector(bigButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //  设置圆角
    self.bigButton.layer.cornerRadius = 20;
    // 这个不知道是啥 设不设置都没影响
    self.bigButton.layer.masksToBounds = NO;
    [self addSubview:self.bigButton];
    
   
    
    //中button
    self.centerButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.centerButton.frame = CGRectMake(137, 370, 100, 40);
//    self.centerButton.backgroundColor = [UIColor redColor];
    [self.centerButton setTitle:@"中" forState:UIControlStateNormal];
    [self.centerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.centerButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [self.centerButton addTarget:self action:@selector(centerButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //  设置圆角
    self.centerButton.layer.cornerRadius = 20;
    // 这个不知道是啥 设不设置都没影响
    self.centerButton.layer.masksToBounds = NO;
    [self addSubview:self.centerButton];
    
    
    //小button
    self.littleButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.littleButton.frame = CGRectMake(237, 370, 100, 40);
//    self.littleButton.backgroundColor = [UIColor redColor];
    [self.littleButton setTitle:@"小" forState:UIControlStateNormal];
    [self.littleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.littleButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    [self.littleButton addTarget:self action:@selector(littleButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    //  设置圆角
    self.littleButton.layer.cornerRadius = 20;
    // 这个不知道是啥 设不设置都没影响
    self.littleButton.layer.masksToBounds = NO;
    [self addSubview:self.littleButton];
    
    self.aboutOurButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.aboutOurButton.backgroundColor = [UIColor colorWithRed:162/255.0 green:135/255.0 blue:191/255.0 alpha:1.0];
    self.aboutOurButton.frame = CGRectMake(15, 460, self.frame.size.width - 30, 100);
    [self.aboutOurButton setTitle:@"关于我们" forState:UIControlStateNormal];
    [self.aboutOurButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.aboutOurButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
    //  设置圆角
    self.aboutOurButton.layer.cornerRadius = 20;
    // 这个不知道是啥 设不设置都没影响
    self.aboutOurButton.layer.masksToBounds = NO;
    [self addSubview:self.aboutOurButton];
    
    
}
-(void)cleanButtonAction:(UIButton *)button
{
    CABasicAnimation *basicAnimation = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
    //缩放时长
    [basicAnimation setDuration:0.5];
    //缩放次数
    [basicAnimation setRepeatCount:1];
    //设置缩放起始值
    basicAnimation.fromValue = [NSNumber numberWithInt:0];
    
    //设置缩放  终止值
    basicAnimation.toValue = [NSNumber numberWithInt:1];
    [self.cleanView.layer addAnimation:basicAnimation forKey:@"basicAnimation"];
    

}
-(void)nightModeButtonAction:(UIButton *)button
{
    if ([NightModeHandle shareNightModeHandle].temp == NO) {
        //layer 层动画
        CATransition *transition = [CATransition animation];
        
        //动画效果
        transition.type = @"fade";
        //动画方向
        [transition setSubtype:kCATransitionFromBottom];
        
        //动画时长
        [transition setDuration:0.8];
        //动画重复次数 nsintegerMaximum 无限次数
        [transition setRepeatCount:1];
        //给myView的layer属性添加一个动画效果
        [self.nightModeView.layer addAnimation:transition forKey:@"transition"];
        [self.layer addAnimation:transition forKey:@"transition"];
        self.nightModeView.backgroundColor = [UIColor colorWithRed:48/255.0 green:64/255.0 blue:83/255.0 alpha:1.0];
        self.backgroundColor = [UIColor colorWithRed:48/255.0 green:64/255.0 blue:83/255.0 alpha:1.0];
        [NightModeHandle shareNightModeHandle].nightModeColor = [UIColor colorWithRed:48/255.0 green:64/255.0 blue:83/255.0 alpha:1.0];
        [NightModeHandle shareNightModeHandle].allViewColor = [UIColor colorWithRed:48/255.0 green:64/255.0 blue:83/255.0 alpha:1.0];
        
    }
    if ([NightModeHandle shareNightModeHandle].temp == YES) {
        //layer 层动画
        CATransition *transition = [CATransition animation];
        
        //动画效果
        transition.type = @"fade";
        //动画方向
        [transition setSubtype:kCATransitionFromBottom];
        
        //动画时长
        [transition setDuration:0.8];
        //动画重复次数 nsintegerMaximum 无限次数
        [transition setRepeatCount:1];
        //给myView的layer属性添加一个动画效果
        [self.nightModeView.layer addAnimation:transition forKey:@"transition"];
        [self.layer addAnimation:transition forKey:@"transition"];
        self.nightModeView.backgroundColor = [UIColor colorWithRed:162/255.0 green:135/255.0 blue:191/255.0 alpha:1.0];
        self.backgroundColor = [UIColor whiteColor];
        [NightModeHandle shareNightModeHandle].nightModeColor = [UIColor colorWithRed:162/255.0 green:135/255.0 blue:191/255.0 alpha:1.0];
        [NightModeHandle shareNightModeHandle].allViewColor = [UIColor whiteColor];
        
    }
    [NightModeHandle shareNightModeHandle].temp = ![NightModeHandle shareNightModeHandle].temp;
}
-(void)bigButtonAction:(UIButton *)button
{
    //layer 层动画
    CATransition *transition = [CATransition animation];
    
    //动画效果
    transition.type = @"fade";
    //动画方向
    [transition setSubtype:kCATransitionFromBottom];
    
    //动画时长
    [transition setDuration:0.8];
    //动画重复次数 nsintegerMaximum 无限次数
    [transition setRepeatCount:1];
    //给myView的layer属性添加一个动画效果
    [self.wordSizeView.layer addAnimation:transition forKey:@"transition"];
    self.wordSizeView.backgroundColor = [UIColor colorWithRed:237/255.0 green:83/255.0 blue:102/255.0 alpha:1.0];
    [WordSizeHandle shareWordSizeHandle].wordViewColor = [UIColor colorWithRed:237/255.0 green:83/255.0 blue:102/255.0 alpha:1.0];
    [WordSizeHandle shareWordSizeHandle].lineTitleSize = 18;
    [WordSizeHandle shareWordSizeHandle].lineOtherSize = 16;
    [WordSizeHandle shareWordSizeHandle].detaiTitleSize = 24;
    [WordSizeHandle shareWordSizeHandle].detaiTextSize = 20;
    [WordSizeHandle shareWordSizeHandle].detaiOtherSize = 17;
    
}
-(void)centerButtonAction:(UIButton *)button
{
    //layer 层动画
    CATransition *transition = [CATransition animation];
    
    //动画效果
    transition.type = @"fade";
    //动画方向
    [transition setSubtype:kCATransitionFromBottom];
    
    //动画时长
    [transition setDuration:0.8];
    //动画重复次数 nsintegerMaximum 无限次数
    [transition setRepeatCount:1];
    //给myView的layer属性添加一个动画效果
    [self.wordSizeView.layer addAnimation:transition forKey:@"transition"];
    self.wordSizeView.backgroundColor = [UIColor colorWithRed:162/255.0 green:135/255.0 blue:191/255.0 alpha:1.0];
    [WordSizeHandle shareWordSizeHandle].wordViewColor = [UIColor colorWithRed:162/255.0 green:135/255.0 blue:191/255.0 alpha:1.0];
    [WordSizeHandle shareWordSizeHandle].lineTitleSize = 16;
    [WordSizeHandle shareWordSizeHandle].lineOtherSize = 14;
    [WordSizeHandle shareWordSizeHandle].detaiTitleSize = 22;
    [WordSizeHandle shareWordSizeHandle].detaiTextSize = 18;
    [WordSizeHandle shareWordSizeHandle].detaiOtherSize = 15;
    
}
-(void)littleButtonAction:(UIButton *)button
{
    //layer 层动画
    CATransition *transition = [CATransition animation];
    
    //动画效果
    transition.type = @"fade";
    //动画方向
    [transition setSubtype:kCATransitionFromBottom];
    
    //动画时长
    [transition setDuration:0.8];
    //动画重复次数 nsintegerMaximum 无限次数
    [transition setRepeatCount:1];
    //给myView的layer属性添加一个动画效果
    [self.wordSizeView.layer addAnimation:transition forKey:@"transition"];
    self.wordSizeView.backgroundColor = [UIColor colorWithRed:0/255.0 green:175/255.0 blue:242/255.0 alpha:1.0];
    [WordSizeHandle shareWordSizeHandle].wordViewColor = [UIColor colorWithRed:0/255.0 green:175/255.0 blue:242/255.0 alpha:1.0];
    [WordSizeHandle shareWordSizeHandle].lineTitleSize = 14;
    [WordSizeHandle shareWordSizeHandle].lineOtherSize = 12;
    [WordSizeHandle shareWordSizeHandle].detaiTitleSize = 20;
    [WordSizeHandle shareWordSizeHandle].detaiTextSize = 16;
    [WordSizeHandle shareWordSizeHandle].detaiOtherSize = 13;
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
